package com.bjtu.literatureclient.controller.sync;

import com.bjtu.literatureclient.api.vo.request.PageListRequest;
import com.bjtu.literatureclient.api.vo.request.SyncEntityRequest;
import com.bjtu.literatureclient.api.vo.response.UserSyncRecord;
import com.bjtu.literatureclient.base.result.Result;
import com.bjtu.literatureclient.domain.user.User;
import com.bjtu.literatureclient.service.sync.SynchronizationService;
import com.bjtu.literatureclient.util.UserUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author caiyuli
 * @date 2020/4/24 2:33 下午
 */

@RestController
@RequestMapping("/sync")
@Api(description = "同步界面的全部接口")
public class SynchronizationController {

    @Autowired
    private SynchronizationService synchronizationService;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation("获取同步的数据列表")
    public PageInfo<UserSyncRecord> syncDataList(@RequestBody @Validated PageListRequest request){
        PageHelper.startPage(request.getPageNo(), request.getPageSize());
        User curUser = UserUtil.getCurUser();
        List<UserSyncRecord> result =  synchronizationService.syncDataList(curUser);
        PageInfo<UserSyncRecord> pageInfos = new PageInfo<>(result);
        return pageInfos;
    }

    @RequestMapping(value = "/entity", method = RequestMethod.POST)
    @ApiOperation("同步数据")
    public Result syncEntity(@RequestBody @Validated SyncEntityRequest request){
        Result result =  synchronizationService.syncEntity(request);
        return result;
    }





}
